package com.woody.aggregate.app.consumer;

import com.alibaba.fastjson.JSON;
import com.woody.aggregate.application.service.contract.ContractService;
import com.woody.common.api.constant.CommonRabbitConstant;
import com.woody.common.api.dto.ContractSyncDTO;
import com.woody.common.task.base.TaskListReq;
import com.woody.common.task.base.TaskReq;
import com.woody.common.web.util.JacksonUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author hzy
 * @date 2025/2/26 下午1:46
 */
@Component
@Slf4j
public class ContractConsumer {


    @Resource
    private ContractService contractService;

    @RabbitListener(
            bindings = @QueueBinding(
                    value = @Queue(value = "contract.queue"),
                    key = CommonRabbitConstant.COMMON_ESIGN_SYNC_KEY_AGGREGATE,
                    exchange = @Exchange(value = CommonRabbitConstant.COMMON_ESIGN_SYNC_EXCHANGE, type = ExchangeTypes.DIRECT)),
            concurrency = "1"
    )
    public void contractSync(TaskListReq taskListReq) {
        log.info("contractSync TaskListReq:{}", JSON.toJSONString(taskListReq));
        TaskReq taskReq = taskListReq.getTaskReqs().get(0);
        ContractSyncDTO msgDTO = JacksonUtil.parseObject(taskReq.getReqBizParam(), ContractSyncDTO.class);

        contractService.contractSync(msgDTO);
        log.info("contractSync end");
    }

}
